var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    username: '',
    userpassword: '',
    localmessage: [{
      username: 'rongmeitiweizhongxin',
      userpassword: 'qzxyrongmeiti999',
      name: '融媒体微中心',
      picture: 'https://cloud-minapp-28782.cloud.ifanrusercontent.com/1mQUWkUZS5I3Z1C8.jpg'
    }, {
      username: 'shijueshejibu',
      userpassword: 'qzxyshijuesheji777',
      name: '视觉设计部',
      picture: 'https://cloud-minapp-28782.cloud.ifanrusercontent.com/1mQUWkWeI3FvlZ2l.jpg'
    }, {
      username: 'zhanluofazhan',
      userpassword: 'qzxyzhanluofazhan666',
      name: '战略发展中心',
      picture: 'https://cloud-minapp-28782.cloud.ifanrusercontent.com/1mQhgFgNrgj07JOv.png'
    }, {
      username: 'qingzeweishi',
      userpassword: 'qzxyweishi1',
      name: '清泽微视',
      picture: 'https://cloud-minapp-28782.cloud.ifanrusercontent.com/1mQUWkCrr7PEAyo5.jpg'
    }, {
      username: 'xinwenzhongxin',
      userpassword: 'qzxyxinwenzhongxin1',
      name: '新闻中心',
      picture: 'https://cloud-minapp-28782.cloud.ifanrusercontent.com/1mQWwMJTqGazflQY.gif'
    }, {
      username: 'zonghebangongshi',
      userpassword: 'qzxybangongshi6',
      name: '综合办公室',
      picture: 'https://cloud-minapp-28782.cloud.ifanrusercontent.com/1mQUWkpppT7XQhc3.jpg'
    }, {
      username: 'wangzhanyunyingzhongxin',
      userpassword: 'qzxywangzhanyunying8',
      name: '网站运营中心',
      picture: 'https://cloud-minapp-28782.cloud.ifanrusercontent.com/1mQW1oUF8T9GYERD.png'
    }],

    isupsucess: false,

  },
  getusername: function (e) {
    console.log(e.detail.value)
    this.setData({
      username: e.detail.value
    })
  },
  getuserpassword: function (e) {
    console.log(e.detail.value)
    this.setData({
      userpassword: e.detail.value
    })
  },
  login: function (e) {
    if (this.data.username == '' || this.data.userpassword == '') {
      wx.showModal({
        title: '提示',
        content: '用户名或密码不能为空',
        success(res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })

    } else {
      var i = 0
      while (i < 8) {
        if (this.data.username == this.data.localmessage[i].username && this.data.userpassword == this.data.localmessage[i].userpassword) {
          wx.setStorageSync('isRegister', true)
          wx.reLaunch({
            url: '../home/home?id=' + i + '&ifenter=1'
          })
          wx.showToast({
            title: '成功',
            icon: 'success',
            duration: 2000
          })
          this.setData({
            isupsucess: true
          })
          app.globalData.isRegister = true
          break
        }
        i++;
      }
      if (this.data.isupsucess == false) {
        wx.setStorageSync('isRegister', false)
        wx.showModal({
          title: '提示',
          content: '密码错误！',
          success(res) {
            if (res.confirm) {
              console.log('用户点击确定')
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '登录'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})